How to use Algolia’s Rules feature to create flexible and dynamic search results.
or
relationship to one another.
Conditions can contain a pattern string, anchoring, a context, or filters, though none are required.
To decide if a rule’s consequences should be applied, Algolia:
is
, contains
, starts with
, and ends with
. The anchoring determines what part of the query the pattern must match: all of it, part of it, the beginning, or the end.
alternatives
in the condition, user queries can match the condition’s pattern, even if the query is a plural, synonym, or typo of the pattern. If you don’t enable alternatives
, user queries must exactly match the condition’s pattern string and anchoring.
ruleContexts
.
is
anchoring, Algolia applies the rule if users haven’t yet entered a query.
If a condition has neither pattern, anchoring, context, or filters, it’s a conditionless rule, and Algolia applies it to every search.
Rules can respond to different types of conditions:
is
anchoringsale
and nothing else.
If the query contains other words, the rule isn’t triggered.
contains
anchoringfeatured
.
The query can include other words.
mobile
in the ruleContexts
.
{ "filters": "category:TV" }
is applied to the query.
OR
combination of different attributes. For example, "filters": "brand:Guess OR color:orange"
returns an error.featured
, the search includes category:TV
in its filters
, and includes mobile
in its ruleContexts
.
aroundRadius
if your user’s query includes the words “near me”.filters
or optionalFilters
matching the query to the results.is
anchoring, but set the text to be an empty string, or leave it blank in the dashboard.
{"filters": "category:TV"}
, if category
is filtered on the value TV
, and on this value only.
Other filters like "category:Smartphone"
or "category:TV OR category:Smartphone"
don’t trigger the rule.
The primary goal of this condition is to create rules that are triggered on specific category pages or when a user applies specific filters.
For example, you can define a rule with the condition {"filters": "category:TV"}
and a consequence to promote specific items.
The rule would be triggered when a user lands on the TV category page.
For more information, see Filters can trigger rules.
attributesForFaceting
.ruleContexts
parameter of a user’s search.
ruleContexts
search parameter.
Consequence | Why is it deactivated? |
---|---|
Pin an item | The same item would always appear in the same position, usually at the top, for all queries and all users. Instead, consider adding a banner to promote items you want to pin. |
Remove Word, Replace Word, Replace Query. | Since there’s no query, there are no words to remove or replace. |
Filter/Boost Matching Attributes | Rules that filter and boost facets require users to type a facet attribute into the query. Since there’s no query or facet in the condition, there’s no filter for the rule to boost |
Option | Capabilities |
---|---|
Visual Editor | • Promote and hide items • Boost, bury, and filter categories • Set priority on category ordering • Ban categories of items • Merchandise on filter selection • Merchandise based on date range, for time-limited promotions • Merchandise based on geolocation, device, and user segment • Facet merchandising (facet type and value reordering) • Display banners • Configurable preview UI |
Manual Editor | • Merchandise on filter selection • Add custom data to rules • Display advanced banners |
Rules API | • Explore the Rules API • Build a custom merchandising UI |